
#include "Logger/ConsoleLogger.h"
#include "Logger/CoutMutex.h"

namespace logger {

std::shared_ptr<Logger> ConsoleLogger::instance() {
    static std::shared_ptr<Logger> singleConsoleLogger = std::shared_ptr<ConsoleLogger>(new ConsoleLogger);
    return singleConsoleLogger;
}

void ConsoleLogger::emit(
    Level level,
    std::chrono::system_clock::time_point time,
    const char* text) {
    if (m_coutMutex) {
        std::lock_guard<std::mutex> lock(*m_coutMutex);
        std::cout << m_logFormatter.format(level, time, text) << std::endl;
    }
}

ConsoleLogger::ConsoleLogger() : Logger(MV_DEFAULT_LOG_LEVEL), m_coutMutex{getCoutMutex()} {
}

std::shared_ptr<Logger> getConsoleLogger() {
    return ConsoleLogger::instance();
}

}  // namespace logger
